﻿//-----------------------------------------------------------------------
// <copyright file="MergeableObject.cs" company="Bluefragments">
//     Copyright (c) Bluefragments. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;

namespace Quebec.Silverlight.Base
{
    /// <summary>
    /// Mergeable Object.
    /// </summary>
    /// <remarks></remarks>
	public abstract class MergeableObject : ObservableObject
	{
        /// <summary>
        /// Occurs when [merged].
        /// </summary>
        /// <remarks></remarks>
		public event EventHandler Merged;

        /// <summary>
        /// Gets the merge ID.
        /// </summary>
        /// <remarks></remarks>
		public abstract string MergeID
		{
			get;
		}

        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        /// <remarks></remarks>
		public MergeableObject()
		{
		}

        /// <summary>
        /// Merges the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <remarks></remarks>
		public abstract void Merge(MergeableObject obj);

        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns></returns>
        /// <remarks></remarks>
		public virtual bool Equals(MergeableObject obj)
		{
			if (this.MergeID.ToLower() == obj.MergeID.ToLower())
				return true;
			else
				return false;
		}

        /// <summary>
        /// Called when [merged].
        /// </summary>
        /// <remarks></remarks>
		protected virtual void OnMerged()
		{
			EventHandler mergedHandler = Merged;

			if (mergedHandler != null)
				mergedHandler(this, EventArgs.Empty);
		}
	}
}
